import { defined, ScreenSpaceEventHandler, ScreenSpaceEventType, Viewer } from '@space8/czm-plugin';

// import cameraRotatorIrrigate from './cameraRotatorIrrigate';
import { useStationDataStoreWithOut } from '@/store/modules/stationData';

const stationDataStore = useStationDataStoreWithOut();

export function useCesiumEvent(viewer: Viewer) {
  // 灌片区域，绕点旋转
  // setTimeout(() => {
  //   cameraRotatorIrrigate(viewer);
  // }, 7500);

  const handler = new ScreenSpaceEventHandler(viewer.canvas);
  handler.setInputAction((click) => {
    const pickedObject = viewer.scene.pick(click.position);
    if (
      defined(pickedObject) &&
      defined(pickedObject.id) &&
      defined(pickedObject.id.type) &&
      defined(pickedObject.id.billboard)
    ) {
      if (pickedObject.id.type === 'station') {
        const stcd = pickedObject.id.properties.stcd.getValue();
        const sttp = pickedObject.id.properties.sttp.getValue();
        const stnm = pickedObject.id.properties.stnm.getValue();
        // 调用测站弹窗
        stationDataStore.setStationData({ stcd, sttp, stnm });
      }
    }
  }, ScreenSpaceEventType.LEFT_CLICK);
}
